var fs = require('fs');
var express = require('express');
var multer = require('multer')

var app = express();
var upload = multer({ dest: 'upload/' });

// 单图上传
app.post('/upload', upload.single('logo'), function (req, res, next) {

  const file = req.file;
  console.log('文件类型：%s', file.mimetype);
  console.log('原始文件名：%s', file.originalname);
  console.log('文件大小：%s', file.size);
  console.log('文件保存路径：%s', file.path);
  res.send({ ret_code: '0' });
});

app.get('/form', function (req, res, next) {
  var form = fs.readFileSync('./form.html', { encoding: 'utf8' });
  res.send(form);
});

var temp = []

app.post('/api/saveCode', (req, res) => {
  res.send({
    method: 'POST',
    data: temp
  })
})

app.get('/api/saveCode', (req, res) => {
  console.log(req.query)
  console.log('==='.repeat(10))
  if (req.query.duoban) {
    temp[0] = req.query.duoban
  } else {
    console.log(temp)
  }


  res.send({
    message: "请求成功",
    status: "success",
    method: 'GET',
    data: temp
  })
})

app.listen(3000);
console.log('Server runing 3000 port....')